/**
 * Created by Kpeng on 2017/7/10.
 * Depending on the jquery-1.11.3.min.js.
 * Depending on the style.css.
 * To cite this document, always state the source as shown above.
 */

$(function () {
    wzERP.Currency.init();
});

wzERP.Currency.init = function () {
    wzERP.Currency.dataHandle(); //添加国家地区
    wzERP.Currency.delHandle(); //删除国家地区
    wzERP.Common.checkBoxVal('.toggle.checkbox input', "本位币只能存在", 1);
};

//新增编辑操作
wzERP.Currency.dataHandle = function () {
    var opt = {
        addBtn: '#addBtn',
        wrapper: "#main",
        container: ".table-edit tbody",
        submitForm: "#submitForm",
        saveBtn: ".saveBtn",
        editBtn: ".editBtn",
        cancelBtn: ".cancelBtn",
        saveFn: function () {
            var curRow = this.event.parents('tr'),
                //错误回调
                errFn = function () {
                    curRow.addClass('editing');
                    return false;
                },
                //成功回调
                successFn = function () {
                    wzERP.Common.delayReload(wzERP.delayTime);
                };
            wzERP.Common.saveHandle("#submitForm", "#currencyAddUrl", this.event, '', successFn, errFn);
        }
    };
    wzERP.Common.editTable(opt);
};

//删除操作
wzERP.Currency.delHandle = function () {
    /*var opt = {
        ele: '.delBtn',
        modalBox: '#modal',
        modalTitleStr: '',
        onApprove: function () {
            wzERP.Common.deleteData('#delCurrencyUrl', $(this).find('.setId'));
        },
        snippets: $('#delCurrencyPageUrl').val()
    };
    wzERP.Common.handleData(opt);*/
    
    $('#main').on('click', '.delBtn', function () {
        var $self = $(this);
        layer.alert('确定删除该货币吗？', {
                title: '提示信息',
                btn: ['取消', '确认'],
                btn1:function(index){
                    layer.close(index)
                },
                btn2:function(){
                    wzERP.Common.deleteData('#delCurrencyUrl', $self)
                }
            }
        );
    })
};
